/**
 * 
 */
package com.geekteam.masterenglish.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.geekteam.masterenglish.R;
import com.geekteam.masterenglish.ui.fragment.HomeFragment;

/**
 * @author MTROL
 *
 */
abstract public class BaseActivity extends SherlockFragmentActivity{

	protected Fragment mContent;
	private OnFragmentChangeListener mFragmentChangeListener;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}
	
	public void switchFragment(Fragment fragment){
		FragmentTransaction transaction = getSupportFragmentManager()
				.beginTransaction();
		transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
				.replace(R.id.content_frame, fragment)
				.addToBackStack(null).commit();
		if(mFragmentChangeListener!=null){
			mFragmentChangeListener.onFragmentChange(fragment instanceof HomeFragment);
		}
	}

	public void switchFragment(Fragment fragment, String tag){
		FragmentTransaction transaction = getSupportFragmentManager()
				.beginTransaction();
		transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
				.replace(R.id.content_frame, fragment, tag)
				.addToBackStack(tag).commit();
		if(mFragmentChangeListener!=null){
			mFragmentChangeListener.onFragmentChange(fragment instanceof HomeFragment);
		}
	}
	
	public OnFragmentChangeListener getFragmentChangeListener() {
		return mFragmentChangeListener;
	}

	public void setFragmentChangeListener(OnFragmentChangeListener fragmentChangeListener) {
		this.mFragmentChangeListener = fragmentChangeListener;
	}
	
	public interface OnFragmentChangeListener{
		public void onFragmentChange(boolean isHome);
	}
}
